package com.global.emc.spring.exception.handler;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.global.emc.core.exception.IEMCException;
import com.global.emc.core.exception.handler.IConvertEMCExceptionHandler;

/**   
 *  
 * @Description:  [将非EMCException类型异常转换为EMCException类型]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年2月20日 下午11:23:45]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年2月20日 下午11:23:45]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
public class ConvertEMCExceptionHandlerManager {
	
	private List<IConvertEMCExceptionHandler> convertEMCExceptionHandlers;

	public List<IConvertEMCExceptionHandler> getConvertEMCExceptionHandlers() {
		return convertEMCExceptionHandlers;
	}

	public void setConvertEMCExceptionHandlers(List<IConvertEMCExceptionHandler> convertEMCExceptionHandlers) {
		this.convertEMCExceptionHandlers = convertEMCExceptionHandlers;
	}

	public IEMCException convertException(HttpServletRequest request, HttpServletResponse response, Object handlerMethod, Exception exception) {
		if(null == convertEMCExceptionHandlers)
			return (IEMCException) exception;
		
		for(IConvertEMCExceptionHandler convertEMCExceptionHandler : convertEMCExceptionHandlers){
			if(convertEMCExceptionHandler.supports(exception)){
				return convertEMCExceptionHandler.convertMessagesToEMCException(exception);
				
			}
		}
		return (IEMCException) exception;
	}

}
